package org.mineground.commands.irc;

import org.jibble.pircbot.Colors;
import org.jibble.pircbot.User;
import org.mineground.Main;
import org.mineground.handlers.irc.CommandExecutor;
import org.mineground.handlers.irc.UserLevel;
import org.mineground.player.PasswordHandler;

/**
 * @name ChangePlayerPassword.java
 * @author Daniel Koenen (2012)
 */
public class ChangePlayerPassword implements CommandExecutor {
    @Override
    public void onCommand(User sender, UserLevel level, String channel, String command, String args[]) {
	if (level.compareTo(UserLevel.IRC_SOP) < 0) {
	    return;
        }

	if (args.length < 2) {
	    Main.getInstance().getIRCHandler().sendMessage(channel, Colors.RED + "* Usage:" + Colors.NORMAL + " !changeplayerpassword [playername] [new password]");
	    return;
	}
        
        if (!PasswordHandler.forceChangePassword(args[0], args[1])) {
            Main.getInstance().getIRCHandler().sendMessage(channel, Colors.RED + "Error: Incorrect player name.");
            return;
        }
        
        Main.getInstance().getIRCHandler().sendMessage(channel, Colors.DARK_GREEN + "Player password has been changed.");
    }
}
